//
//  SwitchViewController.m
//  SwitchView
//
//  Created by xjq on 16/2/22.
//  Copyright © 2016年 xjq. All rights reserved.
//

#import "SwitchViewController.h"

#import "BlueViewController.h"
#import "YellowViewController.h"


@interface SwitchViewController ()

@property(nonatomic,strong)BlueViewController *blueVC;
@property(nonatomic,strong)YellowViewController *yellowVC;

@property(nonatomic,assign)BOOL curBlue;
@end

@implementation SwitchViewController

-(BlueViewController *)blueVC
{
    if (_blueVC == nil) {
        _blueVC = [[BlueViewController alloc]init];
    }
    return _blueVC;
}

-(YellowViewController *)yellowVC
{
    if (_yellowVC == nil) {
        _yellowVC = [[YellowViewController alloc]init];
    }
    return _yellowVC;
}


- (IBAction)TouchChange:(id)sender
    {
        //插入动画效果（UIView简单切换动画）
        [UIView beginAnimations:@"ViewFlip" context:nil];
        //动画的时间
        [UIView setAnimationDuration:1.25];
        //运动方式
        [UIView setAnimationCurve:UIAccessibilityAnnouncementNotification];

        
    if (self.curBlue) {
        [self.view insertSubview:self.yellowVC.view atIndex:0];
        [self.blueVC.view removeFromSuperview];
        
        //运动的样式
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
        
    }
    else
    {
        [self.view insertSubview:self.blueVC.view atIndex:0];
        [self.yellowVC.view removeFromSuperview];
        //动画的样式
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
    }
        //动画开始播放
        [UIView commitAnimations];
        self.curBlue = !self.curBlue;
    
}




- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
//    self.blueVC= [[BlueViewController alloc]init];
//    self.yellowVC = [[YellowViewController alloc]init];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
